﻿using System;
using System.IO;
using System.Windows.Forms;

namespace APP.HELPER.Utils.Shell
{
    public class WebLink
    {
        public static void Create(string linkName, string targetPath, string executePath, string description, string icon)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(targetPath);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
            string text = directoryInfo.FullName + "\\" + linkName + ".lnk";
            FileInfo fileInfo = new FileInfo(text);
            try
            {
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
                ShellShortcut shellShortcut = new ShellShortcut(fileInfo.FullName)
                {
                    Path = executePath,
                    Description = description,
                    IconPath = icon
                };
                shellShortcut.Save();
            }
            catch
            {
                MessageBox.Show("Unable to create link in special directory: " + text, "Shell Link Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
        public static void CreateInternet(string linkName, string targetPath, string executePath, string description, string icon)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(targetPath);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
            string text = directoryInfo.FullName + "\\" + linkName + ".lnk";
            FileInfo fileInfo = new FileInfo(text);
            try
            {
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
                ShellShortcut shellShortcut = new ShellShortcut(fileInfo.FullName)
                {
                    Path = executePath,
                    WorkingDirectory = targetPath,
                    Description = description,
                    IconPath = icon
                };
                shellShortcut.Save();
            }
            catch
            {
                MessageBox.Show("Unable to create link in special directory: " + text, "Shell Link Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
    }
}
